/*
 * 作者：姚俊
 * 功能：查看留言的action
 * 日期：2015-07-05
 */
package admin.action.note;
import java.util.*;

import com.opensymphony.xwork2.ActionContext;

import teacher.bean.Teacher;

import admin.bean.Note;
import admin.service.fruits.NoteService;

public class SearchNoteAction {
	
	private List<Note> notes;
	private int receiveCount;

	public List<Note> getNotes() {
		return notes;
	}

	public void setNotes(List<Note> notes) {
		this.notes = notes;
	}

	public int getReceiveCount() {
		return receiveCount;
	}

	public void setReceiveCount(int receiveCount) {
		this.receiveCount = receiveCount;
	}

	public String execute()
	{
		Teacher tea=(Teacher)ActionContext.getContext().getSession().get("admin");
		this.setReceiveCount(Integer.parseInt(ActionContext.getContext().getSession().get("receiveCount").toString()));
		Note note=new Note();
		note.setState(0);
		note.setToUser(tea.getTeaId());
		this.setNotes(new NoteService().selectAllNote(note));
		
		//当查看过后，把所有查看的信息的状态都变成已经度过的信息，用1来表示
		for(Note n:this.getNotes())
		{
			new NoteService().updateNote(1, n);
		}
		ActionContext.getContext().getSession().put("receiveCount", 0);
		return "succ";
	}

}
